package org.bot.server.login.controller;

import com.alibaba.fastjson.JSONObject;
import org.bot.server.config.LoginCache;
import org.bot.server.utils.BaseController;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;
import java.util.UUID;

/**
 * @Author: 沧月
 * @Date: 2023/12/9 21:29
 * @Description: 描述
 */
@RestController
@RequestMapping("/")
public class LoginController extends BaseController {

    @Value("${bot.login-name}")
    private String userName;

    @Value("${bot.login-password}")
    private String password;

    @RequestMapping("/login")
    public JSONObject login(String userName, String password) {
        if(!(Objects.equals(this.userName,userName) && Objects.equals(this.password,password))){
            return sendError("用户名密码错误");
        }
        String token = UUID.randomUUID().toString();
        LoginCache.addLogin(token);
        return sendData(token);
    }
}
